package com.ego.controller;

import com.ego.commons.pojo.EasyUIDatagrid;
import com.ego.commons.pojo.EgoResult;
import com.ego.pojo.TbItem;
import com.ego.service.TBItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Title
 * @Author Lyg
 * @Description:
 */
@RestController
public class TBItemController {
    @Autowired
    private TBItemService tbItemService;

    @RequestMapping("/item/list")
    public EasyUIDatagrid itemList(int page, int rows){
        return  tbItemService.showItem(page,rows);
    }

    //删除
    @PostMapping("/rest/item/delete")
    public EgoResult deleteItem(long[] ids){
        EgoResult egoResult = tbItemService.updateItemStatusByIds(ids,3);

        return egoResult;
    }
    //上架
    @PostMapping("/rest/item/reshelf")
    public EgoResult reshelf(long[] ids){
        EgoResult egoResult = tbItemService.updateItemStatusByIds(ids,1);
        return egoResult;
    }
    //上架
    @PostMapping("/rest/item/instock")
    public EgoResult instock(long[] ids){

        EgoResult egoResult = tbItemService.updateItemStatusByIds(ids,2);
        return egoResult;
    }

    //新增功能
    @PostMapping("/item/save")
    public EgoResult itemSave(TbItem tbItem, String desc,String itemParams){

        return tbItemService.insert(tbItem,desc,itemParams);
    }
    //修改功能
    @PostMapping("/rest/item/update")
    public EgoResult update(TbItem tbItem,String desc,String itemParams,long itemParamId){

        EgoResult egoResult = tbItemService.update(tbItem,desc,itemParams,itemParamId);

        return egoResult;
    }
}
